package com.xiaozhen.blog.utils;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

public class CookieUtil {

    /**
     *
     * @param request 从哪个请求里面获取
     * @param name 获取的cookie名称
     * @return
     */
    public static String getValue(HttpServletRequest request, String name){
        if (request == null || name == null){
            throw new IllegalArgumentException("参数为空");
        }
        Cookie[] cookies = request.getCookies();
        if (cookies != null){
            for (Cookie c : cookies){
                if (c.getName().equals(name)){
                    return c.getValue();
                }
            }
        }
        return null;
    }
}
